package com.ysmygx.config;

import com.ysmygx.entity.RequestBody;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
@Data
public class RequestBodyFactory {
    /**
     * 客户号
     */
    @Value("${pay.customer-id}")
    private String customerId;
    /**
     * 用户号
     */
    @Value("${pay.user-id}")
    private String userId;


    public <T> RequestBody<T> build(T body){
        RequestBody<T> request = new RequestBody<>(body);
        RequestBody<T>.SysHead sysHead = request.new SysHead();

        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        sysHead.setTranDate(LocalDateTime.now().format(df));
        sysHead.setCustomerId(customerId);
        sysHead.setUserId(userId);
        sysHead.setSeqNo(sysHead.getTranDate());
        request.setSysHead(sysHead);
        return  request;
    }
}
